package com.wwdx.controller.admin;

import com.wwdx.controller.base.BaseController;
import com.wwdx.model.WwdxVipProductModel;
import com.wwdx.model.dto.ResultBean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

/**
 * @author liguoliang
 * @date 2017/10/30 00:30
 */
@Controller
@RequestMapping("/system/wwdx_vip_product")
public class WwdxVipProductController extends BaseController{

    /**
     * 列表
     */
    @RequestMapping("/list")
    public ModelAndView list(WwdxVipProductModel model,
                             @RequestParam(value = "page",defaultValue = "1")Integer page,
                             @RequestParam(value = "rows",defaultValue = "10")Integer rows){

        ModelAndView mav = new ModelAndView();
        mav.addObject("listSize",wwdxVipProductService.selectModelCount(model));
        mav.addObject("list",wwdxVipProductService.selectModelList(model,page,rows));
        mav.addObject("model",model);
        return mav;
    }

    @RequestMapping("/list/json")
    @ResponseBody
    public ResultBean listjson(){
        return renderSuccess(wwdxVipProductService.selectModelList(new WwdxVipProductModel(),1,100));
    }

    /**
     * 新增
     */
    @RequestMapping("/create")
    public ModelAndView create() {
       return new ModelAndView();
    }

    /**
     * 修改
     */
    @RequestMapping("/edit")
    public ModelAndView edit(Long id) {
        ModelAndView mav = new ModelAndView();
        mav.addObject("model", wwdxVipProductService.getById(id));
        return mav;
    }

    /**
     * 新增保存
     */
    @RequestMapping("/save")
    public String save(WwdxVipProductModel model) {
        model.setGmt_created(new Date());
        model.setGmt_modified(new Date());
        wwdxVipProductService.save(model);
        return "redirect:/system/wwdx_vip_product/list";
    }

    /**
     * 修改保存
     */
    @RequestMapping("/update")
    public String update(WwdxVipProductModel model) {
        model.setGmt_modified(new Date());
        wwdxVipProductService.update(model);
        return "redirect:/system/wwdx_vip_product/list";
    }
}